using LiJ.Common.Extention;
using System;
using System.Text;

namespace LiJ.Common.Authrization
{
	/// <summary>
	///  旧应用的授权认证信息
	///  todelete
	/// </summary>
	[Obsolete]
	public class SysAuthorizeInfo : AppAuthorizeInfo
	{
		/// <summary>
		///   从头字符串中初始化签名相关属性信息
		/// </summary>
		/// <param name="signData"></param>
		/// <param name="separator">A=a  B=b 之间分隔符</param>
		public override void FromSignData(string signData, char separator = ';')
		{
			if (!string.IsNullOrEmpty(signData))
			{
				string[] array = signData.Split(separator);
				foreach (string text in array)
				{
					if (!string.IsNullOrEmpty(text))
					{
						string[] array2 = text.Split(new char[1]
						{
							'='
						}, 2);
					    if (array2.Length <= 1) continue;
					    string text2 = array2[1].UrlDecode();
					    switch (array2[0])
					    {
					        case "app_version":
					            base.AppVersion = text2;
					            break;
					        case "token":
					            base.Token = text2;
					            break;
					        case "app_source":
					            base.AppSource = text2;
					            break;
					        case "app_client":
					            base.AppClient = text2;
					            break;
					        case "tenant_id":
					            base.TenantId = text2.ToInt64(0);
					            break;
					        case "sign":
					            base.Sign = text2;
					            break;
					        case "device_id":
					            base.DeviceId = text2;
					            break;
					        case "timespan":
					            base.TimeSpan = text2.ToInt64(0);
					            break;
					        case "ip_address":
					            base.IpAddress = text2;
					            break;
					        case "web_browser":
					            base.WebBrowser = text2;
					            break;
					        case "pro_code":
					            base.ProCode = text2;
					            break;
					    }
					}
				}
			}
		}

		/// <summary>
		///   获取要加密签名的串
		/// </summary>
		/// <param name="separator"></param>
		/// <returns></returns>
		protected internal override StringBuilder GetSignContent(char separator)
		{
			StringBuilder stringBuilder = new StringBuilder();
            AddSignDataValue("app_client", AppClient, separator, stringBuilder);
            AddSignDataValue("app_source", AppSource, separator, stringBuilder);
            AddSignDataValue("app_version", AppVersion, separator, stringBuilder);
            AddSignDataValue("device_id", DeviceId, separator, stringBuilder);
            AddSignDataValue("ip_address", IpAddress, separator, stringBuilder);
            AddSignDataValue("pro_code", ProCode, separator, stringBuilder);
			long num;
			if (TenantId > 0)
			{
				num = base.TenantId;
                AddSignDataValue("tenant_id", num.ToString(), separator, stringBuilder);
			}
			num = TimeSpan;
            AddSignDataValue("timespan", num.ToString(), separator, stringBuilder);
            AddSignDataValue("token", Token, separator, stringBuilder);
            AddSignDataValue("web_browser", WebBrowser, separator, stringBuilder);
			return stringBuilder;
		}
	}
}
